package com.eric.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Value("${file.location}")
    String fileLocation;
    @Value("${file.path}")
    String filePath;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //匹配到resourceHandler,将URL映射至location,也就是本地文件夹
        /*固定编码：filepath，filelocation对应application.yml中对应值
         * "file:///对应的是 String url = req.getScheme() + "://" + req.getServerName() +":"+ req.getServerPort() +"/file"+ format + newName;"中的file
         *
         */
        registry.addResourceHandler(filePath).addResourceLocations("file:///" + fileLocation);//这里最后一个/不能不写
    }
}
